# Path to parent kernel include files directory
# KERNEL_INCLUDE=/usr/src/linux/include
KERNEL_INCLUDE=/lib/modules/$(shell uname -r)/build/include
LIBC_INCLUDE=/usr/include

DEFINES= 

ifeq ($(shell uname -m), ppc64)
DEFINES+=-D__KERNGLUE__	
endif

#options if you have a bind>=4.9.4 libresolv (or, maybe, glibc)
LDLIBS=-lresolv
ADDLIB=

ifeq ($(LIBC_INCLUDE)/socketbits.h,$(wildcard $(LIBC_INCLUDE)/socketbits.h))
  ifeq ($(LIBC_INCLUDE)/net/if_packet.h,$(wildcard $(LIBC_INCLUDE)/net/if_packet.h))
    GLIBCFIX=-include include-glibc/glibc-bugs.h
  endif
endif
ifeq ($(LIBC_INCLUDE)/bits/socket.h,$(wildcard $(LIBC_INCLUDE)/bits/socket.h))
  GLIBCFIX=-include include-glibc/glibc-bugs.h
endif


#options if you compile with libc5, and without a bind>=4.9.4 libresolv
# NOT AVAILABLE. Please, use libresolv.

CC=gcc
# What a pity, all new gccs are buggy and -Werror does not work. Sigh.
#CCOPT=-D_GNU_SOURCE -O2 -Wstrict-prototypes -Wall -g -Werror
CCOPT=-D_GNU_SOURCE -O2 -Wstrict-prototypes -Wall -g
#MST: we don't really need kernel headers
#CFLAGS=$(CCOPT) $(GLIBCFIX) -I$(KERNEL_INCLUDE) -I../include $(DEFINES) 
CFLAGS=$(CCOPT) $(GLIBCFIX) -I$(KERNEL_INCLUDE) $(DEFINES)

MCAST=mcasthandle
IPV4_TARGETS=arping
IPV6_TARGETS=
TARGETS=$(IPV4_TARGETS) $(IPV6_TARGETS) $(MCAST)

#MST: we don't really need kernel headers
#all: check-kernel $(TARGETS)
all: $(TARGETS)

check-kernel:
ifeq ($(KERNEL_INCLUDE),)
	@echo "Please, set correct KERNEL_INCLUDE"; false
else
	@set -e; \
	if [ ! -r $(KERNEL_INCLUDE)/linux/autoconf.h ]; then \
		echo "Please, set correct KERNEL_INCLUDE"; false; fi
endif

modules: check-kernel
	$(MAKE) KERNEL_INCLUDE=$(KERNEL_INCLUDE) -C Modules

clean:
	@rm -f *.o $(TARGETS)
